import { createWebHistory, createRouter, RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    meta: {
      title: "首页",
    },
    component: () => import("~/views/home/index.vue"),
    children: [
      {
        path: "/goods",
        name: "goods",
        component: () => import("~/views/goods/index.vue"),
        meta: {
          title: "商品列表",
        },
       
      },
      {
        path: "/card",
        name: "card",
        component: () => import("~/views/card/index.vue"),
        meta: {
          title: "列表",
          
        },
      },
    ],
  },
  {
    path: "/user",
    name: "user",
    component: () => import("~/views/user/index.vue"),
    meta: {
      title: "用户列表",
      
    },
  },
  {
    path: "/login",
    name: "login",
    component: () => import("~/views/login/index.vue"),
    meta: {
      title: "login page",
    },
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});
router.beforeEach((from, to, next) => {
  //一般路由守卫中会做一些鉴权和权限控制的事情
  if (to.meta && to.meta.title) {
    document.title = to.meta.title as string;
  } else {
    document.title = "index pages";
  }
  next();
});
export default router;
